import request from "@/utils/http";

/**
 * 加入购物车
 */
export const addCartAPI = (skuId, count) => {
  return request({
    url: "/member/cart",
    method: "post",
    data: { skuId, count },
  });
};
/**
 * 请求列表
 */
export const getCartsAPI = () => {
  return request({
    url: "/member/cart",
  });
};
export const updateCartAPI = (selected, id) => {
  // 根据外部传入的 id 如果有救生船 ids 参数
  // 没有的话就保持 undefined
  let ids;
  if (id) ids = [id];
  return request({
    url: `/member/cart/selected`,
    method: "PUT",
    data: { ids, selected },
  });
};
export const updateCartCountAPI = (skuId, { selected, count }) => {
  return request({
    url: `/member/cart/${skuId}`,
    method: "PUT",
    data: { count, selected },
  });
};
/**
 * 删除购物车 id
 */
export const delCartByIdAPI = (id) => {
  return request({
    url: `/member/cart`,
    method: "delete",
    data: { ids: [id] },
  });
};
